<div class="modal" ng-controller="FlowableFormReferencePopupCtrl">
  <div class="modal-dialog modal-wide">
    <div class="modal-content">
      <div class="modal-header" ng-if="popup.state != 'newForm'">
        <button aria-hidden="true" class="close" data-dismiss="modal" ng-click="close()" type="button">&times;</button>
        <h2>
          {{'PROPERTY.FORMREFERENCE.TITLE' | translate}}
          <span ng-show="selectedForm != null"> - {{selectedForm.name}}</span>
          <span ng-show="selectedForm == null"> - {{'PROPERTY.FORMREFERENCE.EMPTY' | translate}}</span>

        </h2>
      </div>
      <div class="modal-header" ng-if="popup.state == 'newForm'"><h2>{{'FORM.POPUP.CREATE-TITLE' | translate}}</h2>
      </div>
      <div class="modal-body-with-overflow" ng-if="popup.state != 'newForm'">
        <div class="detail-group clearfix">
          <div class="col-xs-12">
            <div class="alert alert-error" ng-show="!state.loadingForms && state.formError" translate>
              PROPERTY.FORMREFERENCE.ERROR.FORM
            </div>
          </div>
        </div>
        <div class="detail-group clearfix">
          <div class="col-xs-12 editor-item-picker">
            <div class="col-xs-4 editor-item-picker-component"
                 ng-class="{'selected' : form.formId == selectedForm.formId}"
                 ng-click="selectForm(form, $event)" ng-if="!state.loadingForms && !state.formError"
                 ng-repeat="form in forms">
              <div class="controls">
                <input ng-checked="form.id == selectedForm.id" ng-click="selectForm(form, $event)" type="checkbox"
                       value="option1"/>
              </div>
              <h4>{{form.name}}</h4>
              <img ng-src="{{getModelThumbnailUrl(form.id)}}"/>
            </div>
            <div ng-show="state.loadingForms">
              <p class="loading" translate>PROPERTY.FORMREFERENCE.FORM.LOADING</p>
            </div>
            <div ng-show="!state.loadingForms && forms.length == 0">
              <p translate>PROPERTY.FORMREFERENCE.FORM.EMPTY</p>
            </div>
          </div>
        </div>
      </div>
      <div class="modal-body" ng-if="popup.state == 'newForm'">
        <p>{{'FORM.POPUP.CREATE-DESCRIPTION' | translate}}</p>
        <div class="alert error" ng-if="model.errorMessage && model.errorMessage.length > 0"
             style="font-size: 14px; margin-top:20px">
          <div class="popup-error" style="font-size: 14px">
            <span class="glyphicon glyphicon-remove-circle"></span>
            <span>{{model.errorMessage}}</span>
          </div>
        </div>
        <div class="form-group">
          <label for="newFormName">{{'FORM.NAME' | translate}}</label>
          <input auto-focus class="form-control" custom-keys
                 editor-input-check enter-pressed="ok()" id="newFormName" ng-disabled="model.loading"
                 ng-model="model.form.name"
                 type="text">
        </div>
        <div class="form-group">
          <label for="newFormKey">{{'FORM.KEY' | translate}}</label>
          <input class="form-control" editor-input-check id="newFormKey"
                 ng-disabled="model.loading" ng-model="model.form.key" type="text">
        </div>
        <div class="form-group">
          <label for="newFormDescription">{{'FORM.DESCRIPTION' | translate}}</label>
          <textarea class="form-control" id="newFormDescription" ng-disabled="model.loading"
                    ng-model="model.form.description"
                    rows="5"></textarea>
        </div>
      </div>
      <div class="modal-footer" ng-if="popup.state != 'newForm'">
        <button class="btn btn-primary" ng-click="cancel()" translate>GENERAL.ACTION.CANCEL</button>
        <button class="btn btn-primary" ng-click="newForm()" ng-disabled="state.formError" translate>
          GENERAL.ACTION.NEW-FORM
        </button>
        <button class="btn btn-primary" ng-click="open()" ng-disabled="!selectedForm || state.formError" translate>
          GENERAL.ACTION.OPEN
        </button>
        <button class="btn btn-primary" ng-click="save()" ng-disabled="state.formError" translate>GENERAL.ACTION.SAVE
        </button>
      </div>
      <div class="modal-footer" ng-if="popup.state == 'newForm'">
        <button class="btn btn-primary" ng-click="cancel()" translate>GENERAL.ACTION.CANCEL</button>
        <button class="btn btn-primary"
                ng-click="createForm()"
                ng-disabled="state.formError || model.form.name.length == 0 || model.form.key.length == 0" translate>
          GENERAL.ACTION.CREATE-FORM
        </button>
      </div>
    </div>
  </div>
</div>
